/**************************************************************************************
*
*	Copyright (C) 2010 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	RenderPathLightPrePass
*
*	Description -	A Light Pre-Pass render path implementation.
*					This requires a 3 pass stage.
*					1. Normal + Depth
*					2. Light Buffer
*					3. Composition Pass
*
*	Comments	-	TODO: Make it so that this implementation is derived from 
*						IRenderPass interface.
*
*	Modification History:
*			Name			   Date					Description
*			MrCodeSushi	-	11/26/2012		-	File creation
**************************************************************************************/

#ifndef _PSX_RENDER_PASS_LIGHT_PRE_PASS_H_
#define _PSX_RENDER_PASS_LIGHT_PRE_PASS_H_

#include "PulseSTD.h"
#include "ParameterContainer.h"
#include "RenderEntryList.h"
#include "Array.h"

namespace Pulse
{
	typedef PSX_Pair< ComponentCamera*, CameraRenderPathSettingsFP* > CameraRPSettings;

	class RenderPathLightPrePass
	{
	public:

		RenderPathLightPrePass( void );

		virtual ~RenderPathLightPrePass( void );

		// Used to get the location of techniques
		const CHAR * GetTechniquesPath( void ) const { return PSX_String("LightPrePass\\"); }
		
		const CHAR * GetTechniquesLibraryPath( void ) const { return PSX_String("LightPrePass\\Library.rtl"); }

		// Standard construction of render entries for models
		EErrorCode::Type BuildRenderEntries( const Model *pModel, RenderEntryList *pRenderEntries );

		// Render entry construction for lights
		EErrorCode::Type BuildRenderEntries( ComponentLight *pLight );

		// The render path can handle any extra setup before executing the render view
		//	like setting up lights fore deferred rendering.
		void ExecuteRenderView( RenderView *pView );

		//
		EErrorCode::Type CreateCameraSettings( ComponentCamera *pCamera, CameraRenderPathSettingsLPP **ppOut );

		EErrorCode::Type RemoveCameraSettings( const ComponentCamera *pCamera, const CameraRenderPathSettingsLPP *pSettings );

	protected:

		friend Renderer;

		typedef Array<CameraRPSettings> CameraRPSettingsList;

		virtual EErrorCode::Type Initialize( void );

		virtual void Cleanup( void );

		CameraRPSettings * FindCameraSettings( const ComponentCamera *pCamera );

	private:

		// Cached lighting instances
		///////////////////////////////

		// Point lights
		//	If inside - draw quad
		//  If outside and intersecting near and far plane - draw quad
		//	If outside and intersecting near only - draw back
		//	If outside and intersecting far only - draw front
		//	(else) If outside and none intersecting - draw front

		// Materials
		Material *m_pPointLightMat;		// point light
		Material *m_pPointLightFront;	// point light
		Material *m_pPointLightBack;	// point light
		Material *m_pPointLightQuad;	// point light
		
		// Geometry
		Geometry *m_pPointLightGeo;
		Geometry *m_pGeoQuad;

		CameraRPSettingsList m_viewRPSettings;
	};
}

#endif /* _PSX_RENDER_PASS_LIGHT_PRE_PASS_H_ */